<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddSomeIndexToLoanBeforeTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('user_bank_cards', function (Blueprint $table) {
            $table->dropIndex('user_bank_cards_uid_index');
        });
        Schema::table('user_infos', function (Blueprint $table) {
            $table->index('user_id','user_id');
        });
        Schema::table('user_loan_requests', function (Blueprint $table) {
            $table->index(['current', 'risk_status', 'status'],'current_status_risk_status');
            $table->index('retry','user_loan_requests_retry');
        });
        Schema::table('user_cert_ocrs', function (Blueprint $table) {
            $table->index(['user_id', 'is_valid'],'user_id_is_valid');
            $table->index('upload','upload');
        });
        Schema::table('user_face_failed_logs', function (Blueprint $table) {
            $table->index(['user_id', 'type'],'user_id_type');
        });
        Schema::table('user_bind_card_exceptions', function (Blueprint $table) {
            $table->index('user_id','user_id');
        });
        Schema::table('user_apply_risk_logs', function (Blueprint $table) {
            $table->index('loan_request_id','loan_request_id');
            $table->index('risk_id','risk_id');
        });
        Schema::table('user_auth_step_event_logs', function (Blueprint $table) {
            $table->index(['uid','is_current'],'is_current_uid');
            $table->index('loan_request_id','loan_request_id');
        });
        Schema::table('admin_bank_icons', function (Blueprint $table) {
            $table->index('bank_name','bank_name');
        });
        Schema::table('user_auth_spider_trans_logs', function (Blueprint $table) {
            $table->index('type','type');
            $table->index('loan_request_id','loan_request_id');
        });
        Schema::table('user_bank_cards', function (Blueprint $table) {
            $table->index(['card_num','is_credit'],'card_num_is_valid');
            $table->index('uid','uid');
            $table->index('is_valid','is_valid');
            $table->index('phone_num','phone_num');
        });
        Schema::table('users', function (Blueprint $table) {
            $table->index('nfsp_user_id','nfsp_user_id');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('user_infos', function (Blueprint $table) {
            $table->dropIndex('user_cert_ocrs_user_id_index');
        });
        Schema::table('user_loan_requests', function (Blueprint $table) {
            $table->dropIndex('current_status_risk_status');
        });
        Schema::table('user_cert_ocrs', function (Blueprint $table) {
            $table->dropIndex('user_id_is_valid');
            $table->dropIndex('upload');
        });
        Schema::table('user_face_failed_logs', function (Blueprint $table) {
            $table->dropIndex('user_id_type');
        });
        Schema::table('user_bind_card_exceptions', function (Blueprint $table) {
            $table->dropIndex('user_id');
        });
        Schema::table('user_apply_risk_logs', function (Blueprint $table) {
            $table->dropIndex('risk_id');
            $table->dropIndex('loan_request_id');
        });
        Schema::table('user_auth_step_event_logs', function (Blueprint $table) {
            $table->dropIndex('is_current_uid');
            $table->dropIndex('loan_request_id');
        });
        Schema::table('admin_bank_icons', function (Blueprint $table) {
            $table->dropIndex('bank_name');
        });
        Schema::table('user_auth_spider_trans_logs', function (Blueprint $table) {
            $table->dropIndex('type');
            $table->dropIndex('loan_request_id');
        });
        Schema::table('user_bank_cards', function (Blueprint $table) {
            $table->dropIndex('card_num_is_valid');
            $table->dropIndex('uid');
            $table->dropIndex('is_valid');
//            $table->dropIndex('phone_num');
        });
        Schema::table('users', function (Blueprint $table) {
            $table->dropIndex('nfsp_user_id');
        });
    }
}
